//
//  StockKLineTechBarView.m
//  K线图自治
//
//  Created by LK-IOS on 2017/12/13.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "StockKLineTechBarView.h"
#import "UIColor+StockColorEntension.h"

@interface StockKLineTechBarView()

@property (nonatomic,assign) NSInteger currentButtonTag;

@end


@implementation StockKLineTechBarView


-(UIButton *)volumeButton
{
    if (!_volumeButton)
    {
        _volumeButton = [self createButtonWithTag:1];
        [self addSubview:_volumeButton];
//        _volumeButton.backgroundColor = [UIColor colorWithHexString:@"EE3B3B"];
        _volumeButton.selected = YES;
        _currentButtonTag = _volumeButton.tag;
        [_volumeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.left.top.equalTo(self);
            make.width.equalTo(@((LKScreenW - 10) * 0.25));
        }];
    }
    return _volumeButton;
}
- (UIButton*)macdButton
{
    if (!_macdButton)
    {
        _macdButton = [self createButtonWithTag:2];
        [self addSubview:_macdButton];
        [_macdButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.top.equalTo(self.volumeButton);
            make.left.equalTo(self.volumeButton.mas_right);
        }];
    }
    return _macdButton;
}

- (UIButton*)wrButton
{
    if (!_wrButton)
    {
        _wrButton = [self createButtonWithTag:3];
        [self addSubview:_wrButton];
        [_wrButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.top.equalTo(self.macdButton);
            make.left.equalTo(self.macdButton.mas_right);
        }];
    }
    return _wrButton;
}

- (UIButton*)kdjButton
{
    if (!_kdjButton)
    {
        _kdjButton = [self createButtonWithTag:4];
        [self addSubview:_kdjButton];
        [_kdjButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.top.equalTo(self.wrButton);
            make.left.equalTo(self.wrButton.mas_right);
        }];
    }
    return _kdjButton;
}

#pragma mark private

- (UIButton*)createButtonWithTag:(NSInteger)tag
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tag = tag;
    [button setTitleColor:[UIColor colorWithHexString:@"ADB3C1"] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithHexString:@"687284"] forState:UIControlStateSelected];
    [button.titleLabel setFont:[UIFont systemFontOfSize:12]];
    button.backgroundColor = [UIColor clearColor];
    [button addTarget:self action:@selector(didClick:) forControlEvents:UIControlEventTouchUpInside];
    return button;
}

- (void)didClick:(UIButton*)button
{
    if (_currentButtonTag == button.tag)
    {
        return;
    }
    
    button.selected = !button.selected;
    UIButton *prevButton = [self viewWithTag:_currentButtonTag];
//    prevButton.backgroundColor = [UIColor colorWithHexString:@"EE6363"];
    prevButton.selected = NO;
//    button.backgroundColor = [UIColor colorWithHexString:@"EE3B3B"];
    _currentButtonTag = button.tag;
    
    if (self.delagate && [self.delagate respondsToSelector:@selector(didSelectButton:index:)])
    {
        [self.delagate didSelectButton:button index:button.tag];
    }
}





@end
